﻿using System;
using System.Text;
using System.Collections;
using ShenLan.Calculator;

class Program
{
  static void Main(string[] args)
  {
    string expression;
    Console.Write("请输入表达式:");
    expression = Console.ReadLine();

    try
    {
      GrammerAnalyzer ga = new GrammerAnalyzer(expression);
      ga.Analyze();

      Token[] toks = ga.TokenList;
      for (int i = 0; i < toks.Length; ++i)
      {
        Console.Write(toks[i]);
      }

      SyntaxAnalyzer sa = new SyntaxAnalyzer(toks);
      sa.Analyze();


      Calculator calc = new Calculator(sa.SyntaxTree);
      double value = calc.Calc();

      Console.Write("={0}", value);

      Console.WriteLine("\n解析过程:\n{0}", calc.Log);
    }
    catch (Exception e)
    {
      Console.WriteLine("错误:" + e.Message);
    }

    Console.Read();
  }
}
